package com.zut.interceptor;

import com.zut.pojo.Admin;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/*
    拦截器
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object loginParent = session.getAttribute("loginParent");
        if (loginParent != null) {
            session.setAttribute("sess", "已登录，欢迎进入");
            return true;
        } else {
            session.setAttribute("sess","未登录，请先登录");
            request.getRequestDispatcher("/log-in").forward(request,response);
            return false;
        }

    }
}
